﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Alipay.AopSdk.Core;
using Alipay.AopSdk.Core.Domain;
using Alipay.AopSdk.Core.Request;
using Alipay.Config;
using Microsoft.AspNetCore.Mvc;

namespace Alipay.Core.Demo.Controllers
{
    /// <summary>
    /// 订单退款
    /// </summary>
    public class Refund : Controller
    {
        public IActionResult Index()
        {
            return View();
        }


        /// <summary>
        /// 订单退款
        /// </summary>
        /// <param name="tradeno">商户订单号</param>
        /// <param name="alipayTradeNo">支付宝交易号</param>
        /// <param name="refundAmount">退款金额</param>
        /// <param name="refundReason">退款原因</param>
        /// <param name="refundNo">退款单号</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<JsonResult> Refunds(string tradeno, string alipayTradeNo, string refundAmount, string refundReason, string refundNo)
        {
            /*DefaultAopClient client = new DefaultAopClient(Config.Gatewayurl, Config.AppId, Config.PrivateKey, "json", "2.0",
                Config.SignType, Config.AlipayPublicKey, Config.CharSet, false);*/

            AlipayTradeRefundModel model = new AlipayTradeRefundModel();
            model.OutTradeNo = tradeno;
            model.TradeNo = alipayTradeNo;
            model.RefundAmount = refundAmount;
            model.RefundReason = refundReason;
            model.OutRequestNo = refundNo;

            AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
            request.SetBizModel(model);

            var response = await Configs.client.ExecuteAsync(request);
            return Json(response.Body);
        }

    }
}
